home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 1 / CU Amiga Magazine CD-ROM Special Edition (1995)(EMAP Images)(GB)[Issue 1995-11].iso / Aminet / text / tex / mma2ltx121.lha / mma2ltx / extpro.c next >
C/C++ Source or Header  |  1995-05-16  |  2KB  |  120 lines

  1. /*
  2.  * extpro.c - Copyright (C) 1995 by Giuseppe Ghibo`
  3.  *
  4.  * Written by Giuseppe Ghibo`
  5.  *
  6.  * Version 1.0 - 16 May 1995
  7.  *
  8.  */
  9.  
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include <string.h>
  13. #include <errno.h>
  14.  
  15. typedef int bool;
  16. #ifndef TRUE
  17. #define TRUE 1
  18. #endif
  19. #ifndef FALSE
  20. #define FALSE 0
  21. #endif
  22.  
  23. #define TMPLEN 2048
  24. char tmpbuf[TMPLEN];
  25.  
  26. void main(int argc, char **argv)
  27. {
  28.     FILE *fpin, *fpout;
  29.     char *fnamein, *fnameout, *p;
  30.     bool copylines, mathstart;
  31.  
  32.     if (argc < 3)
  33.     {
  34.         fprintf(stderr,"extpro v1.0 (C) 1995 by Giuseppe Ghibò\n"
  35.                       "Usage:\n"
  36.                       "\textpro <mma psfile> <prologue file>\n\n"
  37.                       "extracts a PS prologue file from a MMA PS file <mma psfile>,\n"
  38.                       "and writes it into <prologue file>.\n");
  39.         exit(1);
  40.     }
  41.     else
  42.     {
  43.         fnamein = argv[1];
  44.         fnameout = argv[2];
  45.     }
  46.  
  47.     if ((fpin = fopen(fnamein,"r")) == NULL)
  48.     {
  49.         fprintf(stderr,"Can't open file `%s' (r): %s\n",
  50.                fnamein, strerror(errno));
  51.         exit(1);
  52.     }
  53.  
  54.     if ((fpout = fopen(fnameout,"w")) == NULL)
  55.     {
  56.         fprintf(stderr,"Can't open file `%s' (w): %s\n",
  57.                 fnameout, strerror(errno));
  58.         exit(1);
  59.     }
  60.  
  61.     fprintf(fpout,"%%%% Mathematica prologue.\n"
  62.                   "%%%% Extracted from a picture saved by Mathematica in 'PS' form.\n%%%%\n");
  63.  
  64.     copylines = FALSE;
  65.     mathstart = FALSE;
  66.  
  67.     while ((fgets(tmpbuf, TMPLEN, fpin) != NULL))
  68.     {
  69.         if ((p = strstr(tmpbuf,"/Mathdict")) && !mathstart)
  70.         {
  71.             copylines = TRUE;
  72.             fputs(p, fpout);
  73.             continue;
  74.         }
  75.         else if (strstr(tmpbuf,"MathPictureStart") && !mathstart)
  76.             mathstart = TRUE;
  77.         else if (strstr(tmpbuf,"/Mlmarg") && !mathstart)
  78.         {
  79.             fprintf(fpout,"/Mlmarg\t\t0 def\n");
  80.             continue;
  81.         }
  82.         else if (strstr(tmpbuf,"/Mrmarg") && !mathstart)
  83.         {
  84.             fprintf(fpout,"/Mrmarg\t\t0 def\n");
  85.             continue;
  86.         }
  87.         else if (strstr(tmpbuf,"/Mbmarg") && !mathstart)
  88.         {
  89.             fprintf(fpout,"/Mbmarg\t\t0 def\n");
  90.             continue;
  91.         }
  92.         else if (strstr(tmpbuf,"/Mtmarg") && !mathstart)
  93.         {
  94.             fprintf(fpout,"/Mtmarg\t\t0 def\n");
  95.             continue;
  96.         }
  97.         else if (strstr(tmpbuf,"/Mwidth") && !mathstart)
  98.             continue;
  99.         else if (strstr(tmpbuf,"/Mheight") && !mathstart)
  100.             continue;
  101.         else if (strstr(tmpbuf,"/Mtransform") && !mathstart)
  102.         {
  103.             fprintf(fpout,"/Mtransform\t\173  \175 bind def\n");
  104.             continue;
  105.         }
  106.         else if (strstr(tmpbuf,"/Mnodistort") && !mathstart)
  107.             continue;
  108.         else if (strstr(tmpbuf,"%!") && mathstart)
  109.             break;
  110.  
  111.         if (copylines)
  112.             fputs(tmpbuf,fpout);
  113.     }
  114.  
  115.     fprintf(fpout,"end\n");
  116.  
  117.     fclose(fpin);
  118.     fclose(fpout);
  119. }
  120.